package com.jet.member.remote.cashier;

import com.jet.core.exception.CustomException;
import com.jet.core.result.ResultCode;
import com.jet.core.result.ResultJson;
import com.jet.member.remote.cashier.vo.MemberCashierLastOrderVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author dcl
 * @since 2025/2/21 15:08
 */
@Component
@Slf4j
public class CashierRemoteFallback implements FallbackFactory<CashierRemoteFeign> {
    @Override
    public CashierRemoteFeign create(Throwable cause) {

        return new CashierRemoteFeign() {

            @Override
            public ResultJson<MemberCashierLastOrderVo> getMemberCashierLastOrder(long merchantNo, String memberId) {
                if (cause instanceof CustomException) {
                    ResultJson<?> result = ((CustomException) cause).getResultJson();
                    return ResultJson.failure(result.getCode(), result.getMsg());
                }
                return ResultJson.failure(ResultCode.SERVICE_ERROR);
            }
        };
    }
}
